package WindwosAPP

import (
	Client "GOChat/golang-tcpserver/client"
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/theme"
	"fyne.io/fyne/v2/widget"
	"github.com/flopp/go-findfont"
	"os"
	"strings"
)

func init() {
	fontPaths := findfont.List()
	for _, path := range fontPaths {
		//我的系统的字体路径
		//Cause: open C:\Windows\Fonts\Alimama_DongFangDaKai_Italic.ttf: The system cannot find the file specified.
		if strings.Contains(path, "C:\\Windows\\Fonts\\STXINWEI.TTF") {
			os.Setenv("FYNE_FONT", path)
			break
		}
	}

}
func Master() {
	APP := app.New()
	w1 := APP.NewWindow("聊天窗口")
	//创建一个widget组件，进行聊天内容的书写
	Text := widget.NewEntry()
	Text.MultiLine = true
	//设置提示框内容
	Text.PlaceHolder = "请将你的心事告诉我，我将给你一个结果"
	//创建一个按钮
	w2 := APP.NewWindow("服务器返回信息端")
	//Gh := color.RGBA{0x66, 0x00, 0x66, 0xff}
	Text2 := widget.NewEntry()
	Text2.MultiLine = true
	w2.SetContent(Text2)
	w2.Resize(fyne.NewSize(483, 463))
	B1 := widget.NewButtonWithIcon("发送", theme.HelpIcon(), func() {
		go p(Text, Text2)
		w2.Show()
	})

	w1.SetContent(container.NewVBox(Text, B1))
	//重置窗口大小
	w1.Resize(fyne.NewSize(306, 100))
	w1.SetMaster()
	w1.ShowAndRun()
}

// p 接收Server发送的信息
func p(Text *widget.Entry, T2 *widget.Entry) {
	t := Client.ClientParserStrings(Text.Text)
	T2.Text = t
	T2.Refresh()
}
